<template>
    <div>
        <el-form :model="zhuceUserForm" ref="ruleForm"  :rules="editRules" label-width="80px" class="demo-ruleForm">

            <el-form-item   label-width="65px" prop="roleid">
                <el-input  type="hidden" v-model="zhuceUserForm.roleid" ></el-input>
            </el-form-item>
            <el-form-item  label-width="65px" prop="rolename">
                <el-input type="hidden" v-model="zhuceUserForm.rolename" ></el-input>
            </el-form-item>
            <el-form-item label="用户名" label-width="65px" prop="username">
                <el-input  v-model="zhuceUserForm.username" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="密码" label-width="65px" prop="password">
                <el-input v-model="zhuceUserForm.password" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="昵称" label-width="65px" prop="usermonicker">
                <el-input v-model="zhuceUserForm.usermonicker" autocomplete="off" onkeyup="this.value=this.value.replace(/\s+/g,'')"></el-input>
            </el-form-item>
            <el-form-item label="手机号" label-width="65px" prop="phone">
                <el-input v-model="zhuceUserForm.phone" autocomplete="off" oninput="value=value.replace(/[^\d]/g,'');if(value.length > 11)value=value.slice(0,11)"></el-input>
            </el-form-item>

            <!--            <el-form-item label="角色" label-width="65px" prop="rolename">-->
            <!--                <el-select v-model="zhuceUserForm.roleid" selected="selected" >-->
            <!--                    <el-option v-for="kind in kinds" :label="kind.rolename" :value="kind.roleid" selected="selected"></el-option>-->
            <!--                </el-select>-->
            <!--            </el-form-item>-->
            <el-form-item label="上传头像"  prop="url"  >
                <el-upload
                        class="avatar-uploader"
                        action="http://192.168.1.37:7000/upload/upload"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                >
                    <img v-if="zhuceUserForm.url" :src="zhuceUserForm.url" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item>
            <span >
                <el-button @click="reback">取 消</el-button>
                <el-button type="primary" @click="gozhuce">确 定</el-button>
            </span>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "zzz",
        data(){
            return{
                //注册表单
                zhuceUserForm:{
                    roleid:"3",
                    rolename:"用户"
                },
                //编辑商品校验规则
                editRules: {
                    username: [
                        {required: true, message: '请设置用户名', trigger: 'blur'},
                        {max:12,min:6, message: '用户名为6-12位', trigger: 'blur'},
                    ],
                    password: [
                        {required: true, message: '请设置密码', trigger: 'blur'},
                        {max:12,min:6, message: '密码为6-12位', trigger: 'blur'},
                    ],
                    usermonicker: [
                        {required: true, message: '请设置昵称', trigger: 'blur'},
                    ],
                    phone: [
                        {required: true, message: '请输入手机号', trigger: 'blur'},
                        {min:11,message: '手机号格式不正确', trigger: 'blur'},
                        {
                            pattern: /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/,
                            message: '请输入正确的手机号码'
                        }
                    ],
                    password: [
                        {required: true, message: '请设置密码', trigger: 'blur'},
                        {max:12,min:6, message: '密码为6-12位', trigger: 'blur'},
                    ],
                }
            }
        },
        methods:{
            //添加用户头像成功后触发的函数
            handleAvatarSuccess(res, file) {
                this.zhuceUserForm.url = res.data;
            },


            //返回login界面
            reback(){
                this.$router.push("/login");
            },
            //去后端注册
            gozhuce(){
                this.$http.post("/user/user/zhuce",this.zhuceUserForm).then(result=>{
                    if (result.data.code===2000){
                        this.$message.success(result.data.msg);
                        this.$router.push("/login");
                    }else{
                        this.$message.error(result.data.msg);
                    }

                })
            },

        },
    }
</script>

<style scoped>

</style>